package com.lpwa.web.controller.map;

import com.lpwa.common.config.Global;
import com.lpwa.common.utils.RedisUtil;
import com.lpwa.common.utils.http.HttpUtils;
import com.lpwa.system.service.ITagDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GetPositionController {
    @Autowired
    private ITagDataService tagDataService;
    @Autowired
    private RedisUtil redisUtil;
    @GetMapping("/getTagPosition")
    public String getTagInfo(){
//        String tagInfo = HttpUtils.sendPost(" http://10.35.76.224:8080/qpe/getTagInfo","version=2");
       return tagDataService.getTagPosition();
    }

    @GetMapping("/getTagPosition1")
    public String getTagPosition(){
        try{
            String httpAddress = Global.getTdmpLeIpAndPort();
            String tagPosition =HttpUtils.sendPost(" http://"+httpAddress+"/qpe/getTagPosition","version=2");
//        String tagPosition = HttpUtils.sendPost(" http://192.168.0.125:8080/qpe/getTagPosition","version=2");
            return tagPosition;
        }catch (Exception e){
            return null;
        }

    }
    @GetMapping("/getProjectInfo")
    public String getProjectInfo(){
        //判断地图信息redis里面是否存在，不存在则到接口中获取
        String httpAddress = Global.getTdmpLeIpAndPort();
        String projectInfo = "";
        if (redisUtil.hasKey("projectInfo")){
            projectInfo = redisUtil.get("projectInfo").toString();
        }else {
            projectInfo = HttpUtils.sendPost(" http://"+httpAddress+"/qpe/getProjectInfo","version=2");
            redisUtil.set("projectInfo",projectInfo);
        }
        return projectInfo;
    }
}
